package cn.edu.hpu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.hpu.dao.WorkerDao;
import cn.edu.hpu.pojo.Group;
import cn.edu.hpu.pojo.Worker;
import cn.edu.hpu.util.TimeUtil;
@Service
@Transactional
public class WorkerService {
	private WorkerDao workerDao;
	
	public Worker findA(Worker w){
		Worker worker =  workerDao.findByUnique("wname", w.getWname());
		if (worker != null && worker.getWpassword().equals(w.getWpassword())) {
			return worker;
		}else {
			return null;
		}
	}
	public List<Worker> findAllByWjob(String wjob){
		return workerDao.findBy("wjob", wjob);
	}
	
	public void save(Worker worker,Group group){
		Worker w = new Worker();
		w.setCreatetime(TimeUtil.getTime());
		w.setWaddress(worker.getWaddress());
		w.setGroup(group);
		w.setWaward(0);
		w.setWcount(0);
		w.setWjob("w");
		w.setWname(worker.getWname());
		w.setWpassword("123");
		w.setWsalary(worker.getWsalary());
		w.setWtel(worker.getWtel());
		workerDao.save(w);
	}
	public void update(Worker worker,Group group){
		Worker w = new Worker();
		w.setWid(worker.getWid());
		w.setCreatetime(TimeUtil.getTime());
		w.setWaddress(worker.getWaddress());
		w.setGroup(group);
		w.setWaward(0);
		w.setWcount(0);
		w.setWjob("w");
		w.setWname(worker.getWname());
		w.setWpassword("123");
		w.setWsalary(worker.getWsalary());
		w.setWtel(worker.getWtel());
		workerDao.update(w);
	}
	public Worker findAById(String id){
		return workerDao.get(id);
	}
	public void delete(String id){
		workerDao.del(id);
	}
	//setter,getter
	public WorkerDao getWorkerDao() {
		return workerDao;
	}
	@Autowired
	public void setWorkerDao(WorkerDao workerDao) {
		this.workerDao = workerDao;
	}
	
	
}
